<template>
  <!-- 方案规划导航栏 -->
   <div style="width: 100%;height: 100%;text-align: center;">

  
    <div id="elePriceDiv" style="display: flex;margin-top: 1vh;" class="box">
 
      <el-form :inline="true" :model="formInline" disabled="disabled" style="margin-left: 1vh;margin-top: 0.5vh;width: 76%;" class="demo-form-inline">
        <el-form-item label="计算状态:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="calculationStatusLabel">
          </el-input>
        </el-form-item>

        <el-form-item label="计算开始时间:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.calculationStartTime"></el-input>
        </el-form-item>

        <el-form-item label="计算结束时间:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.calculationEndTime"></el-input>
        </el-form-item>

        <el-form-item label="计算耗时:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.calculationTime"></el-input>
        </el-form-item>

      </el-form>

      <div id="buttonDiv" style="text-align: right;margin-top: 0.7vh;width: 24%;">
        
        <el-button  v-if="this.suspendCalculatFlag==1" type="primary" @click="suspendCalculat()" >
          <span class="button-text">中止计算</span>
        </el-button>

        <el-button type="primary" @click="buttonClick()" >
          <span class="button-text">{{buttonText}}</span>
        </el-button>

        <el-button type="primary" v-if="form.calculationStatus==2" @click="executeAlgorithm()" >
          <span class="button-text">计算</span>
        </el-button>

      </div>

       
    </div>
  

</div>
  
</template>

<script>
 

  export default {
    name: 'resourceParameters',
    data() {
      return {
        calculationStatusLabel : '',
        suspendCalculatFlag : "0",
        form: {
          id: '',
          calculationStatus: '',
          calculationStartTime: '',
          calculationEndTime: '',
          calculationTime: '',
          projectId : '',
        },
        projectId : '',

        activeDate: '',
        buttonText: '运行', 
      }
    },
    mounted: function() {
      this.projectId = this.$route.query.projectId;
      this.form.projectId = this.projectId;
      this.queryPageData();
    },
    methods: {


      queryPageData : function(){

        var vm = this;
        var schemeId = "";
        vm.suspendCalculatFlag = "0";

        this.$http.post('/iepsapi/ea/algorithm/queryCalculateInfo?schemeId='+schemeId+"&tableName=htp_algorithm_info&projectId="+this.projectId).then((res) => {
          var result = res.data.data;
          if(result){
            vm.form = result;

            if(vm.form.calculationStatus == "1"){
              vm.calculationStatusLabel = '计算中';
              vm.buttonText = '刷新';
              
              var calculationStartTime = vm.form.calculationStartTime;
              var calculationEndTime = vm.form.calculationEndTime;

              // 创建两个Date对象
              var startTime = new Date(calculationStartTime);
              var endTime;
              if(calculationEndTime&&calculationEndTime!="-"){
                endTime = new Date(calculationEndTime);
              }else{
                endTime = new Date();
              }
              
              // 计算两个时间点之间的差值（毫秒）
              var diff = endTime - startTime;
              
              // 将毫秒转换为分钟
              var minutes = Math.floor(diff / (1000 * 60));

              if(minutes>=5){
                vm.suspendCalculatFlag = "1";
                this.$message({
                  message: '当前算法计算时间超过五分钟，请中止计算，校核输入！',
                  type: 'info'
                });
              }else{
                vm.suspendCalculatFlag = "0";
              }
              

            }else if(vm.form.calculationStatus == "2"){
              vm.calculationStatusLabel = '已完成';
              vm.buttonText = '查看结果';
            }else if(vm.form.calculationStatus == "3"){
              vm.calculationStatusLabel = '计算失败！';
              vm.form.calculationStartTime = "-";
              vm.form.calculationEndTime = "-";
              vm.form.calculationTime = "-";
              vm.buttonText = '计算';
              this.$message({
                message: '经算法计算后，得知氢气供应不足，请校准输入数据后，重新进行计算！',
                type: 'info'
              });
            }else if(vm.form.calculationStatus == "0"){
              vm.calculationStatusLabel = '未计算';
              vm.form.calculationStartTime = "-";
              vm.form.calculationEndTime = "-";
              vm.form.calculationTime = "-";
              vm.buttonText = '计算';
            }

          }else{
            vm.calculationStatusLabel = '未计算';
            vm.form = {
              id: '',
              calculationStatus: '0',
              calculationStartTime: '-',
              calculationEndTime: '-',
              calculationTime: '-',
            };

          }
        }).catch((error) => {
          console.log(error);
        });


      }, 
      buttonClick : function(){
        if(this.form.calculationStatus == "0"||this.form.calculationStatus == "3"){
          this.executeAlgorithm();
        }else if(this.form.calculationStatus == "1"){
          this.queryPageData();
        }else{
          this.$parent.buttonClick('planningResults', 'htpdDiv3')
        }
      },
      suspendCalculat: function(){
        
        var vm = this;

        this.$http.post('/iepsapi/ea/algorithm/suspendCalculat?source='+""+"&tableName=htp_algorithm_info"+"&algorithmType=htp&projectId="+this.projectId).then((res) => {
          vm.queryPageData();
        }).catch((error) => {
          console.log(error);
        });

      },


      executeAlgorithm : function(){
        
        const loading = this.$loading({
          lock: true,
          text: '调用算法中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        

        var url = "executeAlgorithmHydrogenTransportPlan";

        var vm = this;

        this.$http.post('/iepsapi/ea/algorithm/'+url+'?projectId='+this.projectId+"&tableName=htp_algorithm_info").then((res) => {
          var result = res.data.data;
          if(result){
            vm.form = result;

            loading.close();
            

            if(vm.form.calculationStatus == "1"){
              vm.calculationStatusLabel = '计算中';
              vm.buttonText = '刷新';
            }else if(vm.form.calculationStatus == "2"){
              vm.calculationStatusLabel = '已完成';
              vm.buttonText = '查看结果';
            }

          }else{
            vm.calculationStatusLabel = '未计算';
            vm.form = {
              id: '',
              calculationStatus: '0',
              calculationStartTime: '-',
              calculationEndTime: '-',
              calculationTime: '-',
            };

          }
        }).catch((error) => {
          console.log(error);
        });


      },
       
    }
  }
</script>




<style scoped> 

 


  /deep/ .el-input__inner { 
      background-color: #202b6180;
      background-image: none;
      border-radius: 4px;
      border: 1px solid #5c7bc5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      color: #f2f2f2;
      display: inline-block;
      font-size: inherit;
      height: 31px;
      line-height: 31px;
      outline: 0;
      padding: 0 15px;
      -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      width: 100%;
  }

  /deep/ .el-input-group__append, .el-input-group__prepend {
    background-color: #305997;
    color: #ffffff;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #506aa7;
    border-radius: 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }


/deep/.el-input.is-disabled .el-input__inner {
    background-color: #0e2c58e3;
    border-color: #E4E7ED;
    color: #C0C4CC;
    cursor: not-allowed;
}


  /* 设定地图的大小 */
  #allmap{
    height: 350px;
    width: 100%;
  }

  .buttonStyle {
    height: 4vh;
    width: 27vh;
    display: inline-block;
    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    cursor: pointer;
    border-radius: 10px;
    font-family: Arial;
    border: none;
    color: #ffffff;
    font-size: 1.6vh;
    background: #1f2c6c3b;
    border-bottom: 1px solid rgb(64, 158, 255);
    margin: 1.5vh 10px;
    text-align: center;
    line-height: 4vh;
    vertical-align: middle;
    text-decoration: none;
  }

  .box{ 
    width: 98%;
    height: 6vh;
    margin: auto;
    border-radius: 5px;
    margin: auto;
    /* background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%); */
  }

  .titleCss{
    font-size: 22px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: #f2f2f2;
  }
</style>
